# write in 2019,6,6
# write by lidabao

from flask import Flask, request, g
from datetime import datetime
from blinker import Namespace
mysignal = Namespace()
visit_signal = mysignal.signal('visit_signal')


def login(sender):
    username = g.username
    ip = request.remote_addr
    now = datetime.now()
    print('{username}@{ip}@{now}'.format(username=username, ip=ip, now=now))
    print(sender)


visit_signal.connect(login)


app = Flask(__name__)


@app.route('/list')
def hello():
    g.username = request.args.get('username')
    visit_signal.send()
    return 'hello this is signal test'


@app.route('/')
def test():
    return 'this is index page!'


if __name__ == '__main__':
    app.run(debug=True)
